package cn.kgm.template.server.controller;

import cn.kgm.core.http.request.BaseController;
import cn.kgm.core.jackson.JsonUtil;
import cn.kgm.template.server.entity.TemplateButton;
import cn.kgm.template.server.service.TemplateButtonService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.time.LocalDateTime;

/**
 * # 技术改变自己 #
 * 模板数据,滑动按钮类型类型
 *
 * @author kapp-i
 * @date 2024-03-18 15:36:58
 */
@Slf4j
@SpringBootTest
class TemplateButtonTestService extends BaseController {

    @Autowired
    private TemplateButtonService templateButtonService;

    @Test
    void page() {
        IPage<TemplateButton> page = getPage();
        LambdaQueryWrapper<TemplateButton> wrapper = Wrappers.lambdaQuery(TemplateButton.builder()
                .build());
        IPage<TemplateButton> pages = templateButtonService.page(page, wrapper);
        log.info("TemplateButtonTestService::page===>{}", JsonUtil.toJson(pages.getRecords()));
    }

    @Test
    void get() {
        Long id = 1L;
        TemplateButton templateButton =templateButtonService.getById(id);
        log.info("TemplateButtonTestService::get===>{}", JsonUtil.toJson(templateButton));
    }

    @Test
    void save() {
        TemplateButton templateButton = TemplateButton.builder()
                .id(1L)
                .infoId(1L)
                .value(true)
                .name("button1")
                .createTime(LocalDateTime.now())
                .updateTime(LocalDateTime.now())
                .build();
            templateButtonService.save(templateButton);
        log.info("TemplateButtonTestService::save===>{}", JsonUtil.toJson(templateButton));
    }

    @Test
    void update() {
        TemplateButton templateButton = TemplateButton.builder()
                .build();
            templateButtonService.updateById(templateButton);
        log.info("TemplateButtonTestService::update===>{}", JsonUtil.toJson(templateButton));
    }

    @Test
    void delete() {
        Long[] ids = new Long[]{0L};
            templateButtonService.update(Wrappers.<TemplateButton>lambdaUpdate()
                .set(TemplateButton::getIsDel, true)
                .in(TemplateButton::getId, ids));
        log.info("TemplateButtonTestService::delete===>{}", JsonUtil.toJson(ids));
    }
}
